let table_name = "article_list_table";
let table_data_url = "/sys/article/list/list";
let number_list = "<'row'<'#mytool.col-xs-3'><'col-xs-9'>><'row'<'.col-xs-12'tr>><'row'<'#num_menu.col-xs-2'l><'col-xs-10'p>>";

function action_status() {
}

let dataManage = {
    currentItem: null,
    fuzzySearch: true,
    getQueryCondition: function (data) {
        let param = {};
        param.start = data.start;
        param.length = data.length;
        return JSON.stringify(param);
    },
};

let returnData = {
    getDate: [
        {
            className: "ellipsis",
            data: "",
            render: CONSTANT.DATA_TABLES.RENDER.ELLIPSIS,
            orderable: false,
            width: "50px"
        }, {
            className: "ellipsis",
            data: "title",
            render: CONSTANT.DATA_TABLES.RENDER.ELLIPSIS,
            orderable: false,
            width: "50px"
        },
        {
            className: "ellipsis",
            data: "url",
            orderable: false,
            width: "50px",
            render: CONSTANT.DATA_TABLES.RENDER.ELLIPSIS,
        }, {
            className: "ellipsis",
            data: "city",
            render: CONSTANT.DATA_TABLES.RENDER.ELLIPSIS,
            orderable: false,
            width: "50px"
        }, {
            className: "ellipsis",
            data: "type",
            orderable: false,
            width: "50px",
            render: function (data, type, row, meta) {
                return row.type;
            }
        },{
            className: "ellipsis",
            data: "wight",
            orderable: false,
            width: "50px",
            render: CONSTANT.DATA_TABLES.RENDER.ELLIPSIS,
        },{
            className: "ellipsis",
            data: "images",
            orderable: false,
            width: "50px",
            render: function (data, type, row, meta) {
                if (isNotNull(row.images)) {
                    return '<img alt="" src="http://img.shengongying.cn/' + row.images + '" width="50px" height="50px">';
                }
            }
        },
        {
            className: "ellipsis",
            data: "",
            orderable: false,
            width: "50px",
            render: function (data, type, row, meta) {
                let button = '';
                button += '<button class="btn btn-sm btn-success" onclick=article_list_delete(' + row.id + ')>删除</button><button class="btn btn-sm btn-info" onclick=article_list_update(' + row.id + ')>修改</button>';
                return button;
            }
        }
    ]
}

function foot_info(result) {
}

function createdRow(row, data, index) {
    if (data.role) {
        $(row).addClass("info");
    }
}

function drawCallback(settings) {
}

function search_user() {
    find();
}

function fn_draw_call_back() {
}


modalClose('article_list_modal', function () {
    $('#article_list_id').val('');
    $('#title').val('');
    $('#city').val('');
    $('#description').val('');
    $('#type').val('');
    $('#url').val('');
    $('#wight').val('');
    $('#video').val('');
    image_item_re_init('');
});

function create_article_list() {
    $('#article_list_modal').modal("show");
}


function save_article_list() {
    let formData = new FormData();
    let id = $('#article_list_id').val();
    formData.append("id", id);

    let title = $('#title').val();
    formData.append("title", title);

    let city = $('#city').val();
    formData.append("city", city);

    let description = $('#description').val();
    formData.append("description", description);

    let type = $('#type').val();
    formData.append("type", type);

    let url = $('#url').val();
    formData.append("url", url);

    let content = $('#_content').val();
    formData.append("content", content);

    let wight = $('#wight').val();
    formData.append("wight", wight);

    let video = $('#video').val();
    formData.append("video", video);

    let file = $('#image')[0].files[0];
    formData.append("file", file);


    HttpUtils.upload_file("/sys/article/list/save", formData, function (result) {
        success_msg("保存成功", function (data) {
            $('#article_list_modal').modal("hide");
            find();
        })
    })

}


function article_list_update(id) {
    HttpUtils.post_json("/sys/article/list/detail", JSON.stringify({"id": id}), function (result) {
        let data = result.data;
        $('#article_list_id').val(data.id);
        $('#title').val(data.title);
        $('#city').val(data.city);
        $('#description').val(data.description);
        $('#type').val(data.type);
        $('#url').val(data.url);
        $('#video').val(data.video);
        $('#wight').val(data.wight);
        init_image_item("http://img.shengongying.cn/"+data.images)
        $('#article_list_modal').modal("show");
    })
}


function article_list_delete(id) {
    HttpUtils.post_json("/sys/article/list/delete", JSON.stringify({"id": id}), function (result) {
        success_msg("删除成功", function () {
            find();
        });
    })
}